package com.laan.plat;

import java.util.ArrayList;

import com.laan.plat.R;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.RectF;

public class Explosions {
	
	private ArrayList<Sprite> explosions;
//	private static final int NUVOLSMAX = 8;
//	private Random rand;
	Resources resources;
	BitmapFactory.Options options;
	
	public Explosions(Resources res) {
		explosions = new ArrayList<Sprite>();
//		rand = new Random();
		options = new BitmapFactory.Options();
		options.inPreferredConfig = Bitmap.Config.ARGB_8888;
		resources = res;
	}
	
	public void actualitza() {
//		toca_afegir();
		for(int i=explosions.size()-1; i>=0; i--) {
			Sprite explo = explosions.get(i);
			explo.actualitza();
			if(explo.finished) explosions.remove(i);
		}
	}
	
	public void draw(Canvas canvas) {
		for(Sprite s: explosions) s.draw(canvas);
	}
	
//	public void afegir(float x, float y, float width, float height) {
//		Bitmap explobmp = BitmapFactory.decodeResource(resources, R.drawable.explosionsprite, options);
//		Sprite explo = new Sprite(explobmp, width, height, 24, 5, 5);
//		explo.setCoords(x, y);
//		explosions.add(explo);
//	}
	
	public void afegir(RectF rec) {
		Bitmap explobmp = BitmapFactory.decodeResource(resources, R.drawable.explosionsprite, options);
		Sprite explo = new Sprite(explobmp, rec.width(), rec.height(), 24, 5, 5, 1);
		explo.setCoords(rec.left, rec.top);
		explosions.add(explo);
	}
}
